package leetcode.code0916;

import java.util.ArrayList;
import java.util.List;

import leetcode.IDebug;

public class Solution implements IDebug {

	public List<String> wordSubsets(String[] words1, String[] words2) {
		int[] dics = new int[26];
		for (String word : words2) {
			int[] cnts = new int[26];
			for (char c : word.toCharArray()) {
				cnts[c - 'a']++;
			}
			for (int i = 0; i < dics.length; i++) {
				dics[i] = Math.max(dics[i], cnts[i]);
			}
		}
		List<String> ans = new ArrayList<>();
		for (String word : words1) {
			int[] cnts = new int[26];
			for (char c : word.toCharArray()) {
				cnts[c - 'a']++;
			}
			boolean ok = true;
			for (int i = 0; i < dics.length; i++) {
				if (cnts[i] < dics[i]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				ans.add(word);
			}
		}
		return ans;
	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
